

// 致力于将接口整合到一个文件中   => 方便维护和管理

// 判断用户名是否存在
request({
    type: "get",
    url: "../php/isExistUser.php",
    data: {
        user,
    },
    dataType: "json",
}).then(result => {
    var { status, result } = result;
    if (status) {
        userSpan.textContent = "√";
        userSpan.className = "user_span right";
        isUserOk = true;
    } else {
        userSpan.textContent = "用户名已被注册";
        userSpan.className = "user_span error";
    }
}).catch(err => {
    throw err;
})

// 注册
request({
    type: "post",
    url: "../php/register.php",
    data: { user, pwd, phone, email },
    dataType: "json",
}).then(result => {
    var { status, message } = result;
    if (status) {
        location.href = "./login.html";
    } else {
        alert(message);
    }
}).catch(err => {
    throw err;
})



request({
    type: "post",
    url: "../php/login.php",
    data: { user, pwd },
    dataType: "json",
}).then(result => {
    var { status, message } = result;
    if (status) {
        setCookie("lgc", user, 31 * 24 * 60 * 60)
        location.href = "index.html";
    } else {
        alert(message);
    }
}).catch(err => {
    throw err;
})